// 7.17.02 Dự trù thuốc, vật tư y
import { BasicColumn, BasicTable, FormSchema, TableAction, useTable } from "@/components/Table";
import { BasicForm, useForm } from "@/components/Form";
import { useTranslation } from "react-i18next";
import Toolbar from "@/components/ViewComponents/Toolbar";
import CreateAndUpdata from "./createAndUpdata";
import { useDrawer } from "@/components/Drawer";
export default function index() {
	const { t } = useTranslation();
	const schemas: FormSchema[] = [
		{
			label: t(`felix_ui.patient_code`),
			field: "patient_code",
			component: "Input"
		},
		{
			label: t(`felix_ui.full_name`),
			field: "full_name",
			component: "Input"
		},
		{
			label: t(`felix_ui.doctor`),
			field: "doctor",
			component: "Input"
		},
		{
			label: t(`felix_ui.unitOfUse`),
			field: "unitOfUse",
			component: "Input"
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t("felix_ui.sq_numb"),
			width: 100,
			// dataIndex: "sq_numb",
			render: (text, record, index) => index * 1 + 1 // 设置序号
		},
		{
			title: t(`felix_ui.patient_code`),
			dataIndex: "patient_code"
		},
		{
			title: t(`felix_ui.pat_category`),
			dataIndex: "category"
		},
		{
			title: t(`felix_ui.full_name`),
			dataIndex: "full_name"
		},
		{
			title: t(`felix_ui.unit_of_measure`),
			dataIndex: "unit_of_measure"
		},
		{
			title: t(`felix_ui.day1`),
			dataIndex: "day1"
		},
		{
			title: t(`felix_ui.day2`),
			dataIndex: "day2"
		},
		{
			title: t(`felix_ui.day3`),
			dataIndex: "day3"
		},
		{
			title: t(`felix_ui.doctor`),
			dataIndex: "doctor"
		},
		{
			title: t(`felix_ui.discharge`),
			dataIndex: "discharge"
		},
		{
			title: t(`felix_ui.total`),
			dataIndex: "total"
		},
		{
			title: t(`flandre_ui.drug_take_mode`),
			dataIndex: "drug_take_mode"
		},
		{
			title: t(`felix_ui.brand`),
			dataIndex: "brand"
		},
		{
			title: t("felix_ui.action"),
			key: "action",
			fixed: "right",
			render: (_, record) => (
				<TableAction
					actions={[
						{
							label: t("felix_ui.edit"),
							onClick: handleEdit.bind(record)
						},
						{
							label: t("felix_ui.delete"),
							popConfirm: {
								title: t("felix_ui.delMessage"),
								confirm: handleDelete.bind(record.patient_code)
							}
						}
					]}
				/>
			)
		}
	];
	const getInfo = () => {
		let arr: any = [
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			},
			{
				patient_code: "adefgsfdda",
				full_name: "嘟嘟嘟",
				category: "2025",
				unit_of_measure: "green",
				day2: "green",
				day1: "lundun",
				day3: "USA",
				doctor: "Felix",
				discharge: "afsgf",
				total: "55",
				drug_take_mode: "dsa",
				brand: "rtygfds"
			}
		];
		return arr;
	};
	const formSchemaBottom: FormSchema[] = [
		{
			label: t("felix_ui.dt_date"),
			field: "dt_date",
			component: "Input"
		},
		{
			label: t("felix_ui.pulse_rate"),
			field: "pulse_rate",
			component: "Input",
			componentProps: {
				suffix: "lần/phút"
			}
		},
		{
			label: t("kevin_ui.temperature"),
			field: "temperature",
			component: "Input",
			componentProps: {
				suffix: "℃"
			}
		},
		{
			label: t("felix_ui.blood_pressure"),
			field: "blood_pressure",
			component: "Input",
			componentProps: {
				suffix: "mm/Hg"
			}
		},
		{
			label: t("felix_ui.breathing"),
			field: "breathing",
			component: "Input",
			componentProps: {
				suffix: "lần/phút"
			}
		},
		{
			label: t("felix_ui.weight"),
			field: "weight",
			component: "Input",
			componentProps: {
				suffix: "kg"
			}
		},
		{
			label: t("felix_ui.care"),
			field: "care",
			component: "Input"
		},
		{
			label: t("felix_ui.place_of_transfer"),
			field: "place_of_transfer",
			component: "Input"
		}
	];
	const [registerTable, { reload }] = useTable({
		// api: productApi.getproductPage,
		dataSource: getInfo(),
		columns,
		formConfig: {
			labelWidth: 120,
			labelWrap: true,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 6 },
			actionColOptions: { span: 24 }
		},
		bordered: true,
		useSearchForm: true
		// searchInfo: {
		// 	bizType: "2"
		// }
		// afterFetch: (res: any) => {
		// 	return res.map((item: any) => mergeObjects(item, item.bloods));
		// }
	});
	const [formBottom] = useForm({
		schemas: formSchemaBottom,
		showActionButtonGroup: false,
		labelWidth: 120,
		baseColProps: { span: 8 }
	});
	const [registerDrawer, { openDrawer }] = useDrawer();
	const handleEdit = (record: any) => {
		openDrawer(true, {
			reload,
			record,
			isUpdated: true
		});
	};
	//删除角色
	const handleDelete = async (id: any) => {
		console.log("id", id);
		// // 发起删除
		// const res = await productApi.deleteproduct(id, "2");
		// reload();
		// if (!res) return message.error(t("viewComponents.patientInformation.deleteFailed"));
		// message.success(t("viewComponents.patientInformation.deleteSuccessfully"));
	};
	const handlerToolbarAction = async (key: string) => {
		switch (key) {
			case "add":
				openDrawer(true, {
					reload,
					isUpdated: false
				});
				break;
		}
	};
	return (
		<div className="page">
			<div className="page-content h-100% flex flex-col justify-between">
				<div className="block h-69%">
					<BasicTable register={registerTable}></BasicTable>
				</div>
				<div className="block h-30%">
					<div className="block-label"> {t("felix_ui.vitalSigns")}</div>
					<BasicForm register={formBottom}></BasicForm>
				</div>
			</div>
			<Toolbar action={handlerToolbarAction} btnList={["add"]} />
			<CreateAndUpdata register={registerDrawer}></CreateAndUpdata>
		</div>
	);
}
